import React, { Component } from 'react';
import { connect } from 'dva';
import { Spin } from 'antd';

class FaultAlarm extends Component<any, any> {
  state = {
    alarmUrl: '',
  };

  componentDidMount() {
    const { dispatch } = this.props;
    dispatch({
      type: 'ejectionModeReport/getData',
      payload: { url: '/audience/group/getBiToken' },
      callback: (res: any) => {
        this.setState({
          alarmUrl: res.data
            ? `https://dftc-bi.dfiov.com.cn/?proc=1&action=viewer&hback=true&db=M18!2f!!5f39!!5c04!!6a21!!5f0f!.db&token=${res.data}`
            : null,
        });
      },
    });
  }

  render() {
    const { alarmUrl } = this.state;
    const {loading}= this.props
    return (
      <div
        style={{
          display: 'flex',
          flexDirection: 'column',
          width: '100%',
          height: 'calc(100vh - 112px)',
          justifyContent: 'center',
        }}
      >
        {loading && <Spin size="large" />}
        {alarmUrl && (
          <iframe
            src={alarmUrl}
            style={{ display: 'block', height: '100%' }}
            width="100%"
            frameBorder="0"
          />
        )}
      </div>
    );
  }
}
export default connect((state: any) => {
  return {
    loading: state.loading.effects['ejectionModeReport/getData'],
  };
})(FaultAlarm);
